package com.whatisjee.ssf.exception;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.whatisjee.ssf.misc.ErrorMessage;

public class BusinessException extends Exception {
	private static final long serialVersionUID = 2277446497443489745L;

	private final List<ErrorMessage> messages;

	public BusinessException(List<ErrorMessage> messages) {
		super();
		this.messages = new ArrayList<ErrorMessage>(messages);
	}

	public BusinessException(String message, Throwable cause,
			List<ErrorMessage> messages) {
		super(message, cause);
		this.messages = new ArrayList<ErrorMessage>(messages);
	}

	public BusinessException(String message, List<ErrorMessage> messages) {
		super(message);
		this.messages = new ArrayList<ErrorMessage>(messages);
	}

	public BusinessException(Throwable cause, List<ErrorMessage> messages) {
		super(cause);
		this.messages = new ArrayList<ErrorMessage>(messages);
	}

	public static BusinessException build(ErrorMessage message) {
		List<ErrorMessage> messages = new ArrayList<ErrorMessage>();
		messages.add(message);
		return (new BusinessException(messages));
	}

	public List<ErrorMessage> getMessages() {
		return Collections.unmodifiableList(messages);
	}

}
